//ajax发送时将token放在header中发送
$(document).ajaxSend(function(event,xhr,options){
    xhr.setRequestHeader("user_token", localStorage.getItem("userToken"));
});
//统一处理error
$(document).ajaxError(function(event,xhr,options,exc){
    if(xhr.status==401){
        location.href = "blog_login.html";
    }
})

//获取用户信息/作者信息
function getUserInfo(userUrl){
    $.ajax({
        type: "get",
        url: userUrl,
        success: function (ret){
            if(ret != null && ret.code == 200){
                if(ret.data == null){
                    alert("用户信息查询，用户不存在");
                    logout();
                    location.href = "blog_login.html";
                }
                $(".left .card h3").text(ret.data.userName);
                $(".left .card a").attr("href",ret.data.githubUrl);
            }else {
                alert(ret.errMge);
            }
        }
    });
}

//退出登录，删除localStorage信息
function logout(){
    localStorage.removeItem("loginUserId");
    localStorage.removeItem("userToken");
    location.href = "blog_login.html";
}
